Skip to content

added ldap_count_references() #5784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ptomulik
Copy link
Contributor

@ptomulik ptomulik commented Jun 30, 2020

Implemented ldap_count_references() for symmetry with ldap_count_entries(). This is actually just a copy-paste.

Test:

ptomulik@tea:$ LDAP_TEST_HOST=172.25.0.2 LDAP_TEST_BASE="dc=example,dc=org" LDAP_TEST_USER='cn=admin,dc=example,dc=org' LDAP_TEST_PASSWD='admin' sapi/cli/php ./run-tests.php ext/ldap/tests/ldap_count_references_basic.phpt 

=====================================================================
PHP         : /home/ptomulik/sources/php-src/sapi/cli/php 
PHP_SAPI    : cli
PHP_VERSION : 8.0.0-dev
ZEND_VERSION: 4.0.0-dev
PHP_OS      : Linux - Linux tea 5.6.0-2-amd64 #1 SMP Debian 5.6.14-2 (2020-06-09) x86_64
INI actual  : /home/ptomulik/sources/php-src
More .INIs  :   
---------------------------------------------------------------------
PHP         : /home/ptomulik/sources/php-src/sapi/phpdbg/phpdbg 
PHP_SAPI    : phpdbg
PHP_VERSION : 8.0.0-dev
ZEND_VERSION: 4.0.0-dev
PHP_OS      : Linux - Linux tea 5.6.0-2-amd64 #1 SMP Debian 5.6.14-2 (2020-06-09) x86_64
INI actual  : /home/ptomulik/sources/php-src
More .INIs  : 
---------------------------------------------------------------------
CWD         : /home/ptomulik/sources/php-src
Extra dirs  : 
VALGRIND    : Not used
=====================================================================
Running selected tests.
PASS ldap_count_references() - Basic ldap_count_references test [ext/ldap/tests/ldap_count_references_basic.phpt] 
=====================================================================
Number of tests :    1                 1
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    0 (  0.0%) (  0.0%)
Tests passed    :    1 (100.0%) (100.0%)
---------------------------------------------------------------------
Time taken      :    1 seconds
=====================================================================

@cmb69
Copy link
Member

cmb69 commented Jun 30, 2020

cc @MCMic

@ptomulik ptomulik force-pushed the ldap_count_references branch from fefa8a8 to d8d088e Compare June 30, 2020 16:05
@ptomulik ptomulik force-pushed the ldap_count_references branch from d8d088e to 9081faa Compare June 30, 2020 20:12
@MCMic
Copy link
Contributor

MCMic commented Jul 1, 2020

This seems legit as there already is ldap_first_reference, ldap_next_reference, ldap_first_entry, ldap_next_entry and ldap_count_entries.

@php-pulls php-pulls closed this in 915abeb Jul 1, 2020
@ptomulik
Copy link
Contributor Author

ptomulik commented Jul 1, 2020

This is quite off-topic, but I'll try to ask here. Yesterday I was studying the code of openldap and one thing seems little bit inconsistent between OpenLDAP and PHP ext-ldap.

In OpenLDAP the ldapmsg struct is used for all LDAP messages including search result, entry, or reference. No matter, whether a given instance of ldapmsg represents a result, an entry or a reference message, it seems to always work with ldap_{first,next}_{message,entry,reference} as well as with ldap_count_{messages,entries,references}.

In ext-ldap, a PHP resource of type "ldap result" is used for result message and "ldap result entry" for entry or reference. As I understand, we can't pass "ldap result" resource to ldap_next_foo, and we can't pass "ldap result entry" to ldap_first_foo, nor to ldap_count_foo? Also, we're unable to infer from "ldap result entry" resource whether it's an entry or reference. Is there any particular reason for this?

@ptomulik ptomulik deleted the ldap_count_references branch July 1, 2020 07:56
@MCMic
Copy link
Contributor

MCMic commented Jul 1, 2020

@ptomulik I was not able to email you, I got «550 Denied by policy (in reply to end of DATA command)»

This is quite off-topic, but I'll try to ask here. Yesterday I was studying the code of openldap and one thing seems little bit inconsistent between OpenLDAP and PHP ext-ldap.

In OpenLDAP the ldapmsg struct is used for all LDAP messages including search result, entry, or reference. No matter, whether a given instance of ldapmsg represents a result, an entry or a reference message, it seems to always work with ldap_{first,next}_{message,entry,reference} as well as with ldap_count_{messages,entries,references}.

In ext-ldap, a PHP resource of type "ldap result" is used for result message and "ldap result entry" for entry or reference. As I understand, we can't pass "ldap result" resource to ldap_next_foo, and we can't pass "ldap result entry" to ldap_first_foo, nor to ldap_count_foo? Also, we're unable to infer from "ldap result entry" resource whether it's an entry or reference. Is there any particular reason for this?

I guess the original authors of php-ldap thought it wiser to differentiate between an operation result and an entry, it seems convenient to me.

About inferring whether it’s an entry or a reference, what’s the use case here? You should now what you asked for (entry or reference), no?

@ptomulik
Copy link
Contributor Author

ptomulik commented Jul 1, 2020

@ptomulik I was not able to email you, I got «550 Denied by policy (in reply to end of DATA command)»

Well, that's McAfee :)

This is quite off-topic, but I'll try to ask here. Yesterday I was studying the code of openldap and one thing seems little bit inconsistent between OpenLDAP and PHP ext-ldap.
In OpenLDAP the ldapmsg struct is used for all LDAP messages including search result, entry, or reference. No matter, whether a given instance of ldapmsg represents a result, an entry or a reference message, it seems to always work with ldap_{first,next}_{message,entry,reference} as well as with ldap_count_{messages,entries,references}.
In ext-ldap, a PHP resource of type "ldap result" is used for result message and "ldap result entry" for entry or reference. As I understand, we can't pass "ldap result" resource to ldap_next_foo, and we can't pass "ldap result entry" to ldap_first_foo, nor to ldap_count_foo? Also, we're unable to infer from "ldap result entry" resource whether it's an entry or reference. Is there any particular reason for this?

I guess the original authors of php-ldap thought it wiser to differentiate between an operation result and an entry, it seems convenient to me.

About inferring whether it’s an entry or a reference, what’s the use case here? You should now what you asked for (entry or reference), no?

ldap result entry resources for entries and references are not fully interchangeable. For example ldap_parse_reference() will always fail (actually return false) for a true entry resource without any error information. If a resource is provided as an argument to my function (e.g. function __construct($ldapResultResource)), I'm not able to fully validate it in front with is_resource() + get_resource_type(). There also is no php-ldap API for that (openldap seems to provide ldap_msgtype() for that). So, for example debugging gets a little bit harder.

@carusogabriel carusogabriel added this to the PHP 8.0 milestone Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants